import cv2
import numpy as np
from collections import Counter

img = cv2.imread("./data/data_02.jpg")

imgGray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)

# ------ 查看灰度图片 -------
# cv2.imshow('original', imgGray)

# ------ 查看灰度图片形状 --------
print("imgShape:", imgGray.shape)

# ------ 将图片进行灰度化处理 --------
r, b = cv2.threshold(imgGray, 127, 255, cv2.THRESH_BINARY)

cv2.imshow('original', b)
cv2.waitKey(2000)

# ------ 设置打印是完整打印 --------
np.set_printoptions(threshold=np.inf)

# ------ 统计频数 --------
params = Counter(b.flatten())

# ------ 打印干湿比 --------
print("ratio:", params[255] / params[0])

# f = open('rs.txt', 'w')
# f.write(b)
